package de.gameduell.framework.queue {
	import flash.events.EventDispatcher;	

	/**
	 * @author ddoe
	 */
	public class GDAction extends EventDispatcher implements IGDAction {
		private var _function:Function;
		private var _arguments:Array;
		private var _description:String;
		private var _actionQueue:GDActionQueue;
		private var _queueId:String;
		
		public function GDAction(aFunction:Function, aArguments:Array, invokeNow:Boolean = false, aDescription:String = "", queueId:String = null) {
			_queueId     = queueId;
			_function 	 = aFunction;
			_arguments   = aArguments;
			_description = aDescription;
			_actionQueue = GDActionQueue.getInstance();		
			if(invokeNow){
				invoke();
			}
		}
			
		public function invoke():void{
			_actionQueue.add(this, queueId);
		}

		public function get queueId():String{
			return _queueId;
		}		

		public function get description():String{
			return _description + " params: "+_arguments.toString();
		}
		
		public function compute():void {
			_function.apply(_function,_arguments);
			dispatchEvent(new ActionEvent(ActionEvent.DONE));
		}
		
	}
}
